<?php
Yii::import('dao.bidAuction.BidAuction');
Yii::import('dao.auction.AuctionDao');
#require Yii::app()->basePath.'/components/Authorize/autoload.php';
require Yii::app()->basePath.'/vendor/autoload.php';
use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;
define("AUTHORIZENET_LOG_FILE","phplog");
Yii::import('dao.bid.*');
Yii::import('application.components.dao.class.AuctionCreateOrder');
Yii::import('dao.auction.AuctionLiveDao');
Yii::import("application.components.Lock");
Yii::import("application.components.autobid.AutoBidDao");
class TestController extends Controller {
public function actionTestcheck(){
	var_dump(Yii::app()->lock->check('AUTOBID_GEARMAN_LOCK:600'));
	var_dump(Yii::app()->lock->check('AUTOBID_GEARMAN_LOCK:484'));
}   
 public function actionTestrefer(){
        $criteria=new CDbCriteria();
        $criteria->addInCondition("bid_pack_id", array(
            10,11,12,13,14
        ));
        $criteria->addCondition("customer_id=35");
        $earnBid=new EarnedBidLog();
        $bidPackNum=$earnBid->count($criteria);
        var_dump($bidPackNum);
        if ($bidPackNum<=0){
            var_dump("第一次购买bidpack");
        }else{
            var_dump("不是第一次购买");
        }
    }
    
    public function actionTestautobid(){
        $autobidDao=new AutoBidDao();
        $customers=$autobidDao->getAutoBidList(1);
        foreach ($customers as $customer){
            var_dump($customer);
        }
    }
    
    public function actionTest168(){
        $product=new AuctionParame();
            $product=  $product->findByAttributes([
                "auction_id"=>292,
                "parame_name"=>"sku"
            ]);
	var_dump($product);
	var_dump($product->sku);
    }
    
    public function actionTest67(){
          echo "<a href='".Yii::app()->baseUrl."/test/test68'>测试</a>"; 
    }
    
    public function actionTest68(){
        var_dump(Yii::app()->getRequest()->url);
        var_dump(Yii::app()->getRequest()->urlReferrer);
    }
    
    public function actionTest66(){
        $url=AuctionInfo::getDetailUrl("haha", 2);
        var_dump($url);
    }
    
    
    public function actionTest65(){
        $this->render('/mail/win_auction',array(
            'USER_NAME'=>'wlvgfe',
            'CREDITS_PRICE'=>'123',
            'CREDITS_AMOUNT'=>'123',
            'AUCTION_NAME'=>'Test auction',
            'TOTAL_COST'=>'120',
            'CURRENT_PRICE'=>100,
            'SHIPPING_COSTS'=>10,
            'email'=>'1028489713@qq.com',
            'code'=>123,
            'code_user'=>'wlvgfe',
            'PRIZE_NAME'=>'wlvgfe',
            'AMOUNT'=>123,
            'DATE_OF_WIN'=>124345,
            'LAST_DAY'=>123,
            'LINK_TO_PAY'=>'www.baidu.com',
            'friend_name'=>'xialuo',
            'friend_message'=>'come here',
            'username'=>'wlvgfe',
            'url'=>'http://www.baidu.com',
            'USERNAME'=>'wlvgfe',
            'PRODUCT_NAME'=>'radio',
            'WIN_DATE'=>'2015-6-25',
            'INVOICE_NUMBER'=>120,
            'SHIPPING_REFERENCE'=>'Shiping',
            "URL"=>'http://pa.infinitenine.com/01.frontend/myaccount/wonauctions/4',
            "PASSWORD"=>'123'
        )); 
    }
    public function actionTest64(){
        $dao=new AuctionLiveDao();
        $dao->find(260);
        var_dump($dao->attributes);
        
            /* $earnedbidlog=new EarnedBidLog();
	        $bidsNum=200;
	        $earnedbidlog->customer_id=1314;
	        $earnedbidlog->amount=1314;
	        $earnedbidlog->note="Buy bidPack Auction "." 1314 Bids";
	        $earnedbidlog->value=100;
	        $earnedbidlog->bid_pack_id=1;
	        $earnedbidlog->bid_source_type=1;//buy bid pack
	        $earnedbidlog->bid_type=1;//CASH bid
	        $earnedbidlog->created=time();
	        $earnedbidlog->save();  */
    }
    
    public function actionPayment(){
        $this->breadcrumbs = array("Bid Packs","PAYMENT BID PACK");
        if(empty(yii::app()->user->id)){
            Yii::app()->runController('login/index/url/buybid');
            die;
        }
        $customerOrderBillingInfoModel = new CustomerOrderBillingInfo('checkout');
    
        $model = $customerOrderBillingInfoModel->find('customer_id = '.Yii::app()->user->id);
    
        if(empty($model)){
            $model = $customerOrderBillingInfoModel;
        }else{
            $model->scenario = 'checkout';
        }
        $model->credit_card_exp_month = date('m');
        $id = Yii::app()->request->getParam('id',null);
        $_buyBidPackIdsarr= explode(",", $this->_buyBidPackIds);
        if(!in_array($id, $_buyBidPackIdsarr)){
            Yii::app()->getRequest()->redirect(Yii::app()->createUrl('buybid'));
            die;
        }
    
        $buyBidPackInfo = $this->getBidPackInfo();
        // var_dump($buyBidPackInfo['bidtypearray']);die;
        $ProductResource=new ProductResource();
        $resource= $ProductResource->find('product_id='.$id);
        $resource_img= new ResourceImg();
        $url=$resource_img->find('id = '.$resource->resource_id);
        	
        $this->render('payment',array(
            'buyBidPackInfo' => $buyBidPackInfo,
            'bidPackId' => 	$id,
            'model' => $model,
            'url'=>$url->path,
        ));
    }
    
    public function actionTest63(){
    $auction=new AuctionDao();
        $auction->find(263);
        $typeLimits=array(15,6,5,4,3);
        $types=array('regular','bidpack','bronze','silver','gold');
        $limitNum=15;
        $type='regular';
        if (!empty($auction) && $auction->type>=1){
            $limitNum=$typeLimits[$auction->type-1];
            $type=$types[$auction->type-1];
        }
        /* $liveLimitSql='
                    SELECT
                    	COUNT(orders.auction_id)
                    FROM
                    	orders
                    LEFT JOIN auction_parame ON orders.auction_id = auction_parame.auction_id
                    WHERE
                    	auction_parame.parame_name = "type"
                    AND
                        auction_parame.parame_value = 3
                    AND 
                        orders.customer_id = 1030
                    AND
                        orders.created>=1451121732
                '; */
        $sql='select count(id) from auction_info where id=100';
        $liveLimitNum=Yii::app()->db->createCommand($sql)->queryRow();
        var_dump($liveLimitNum);
    }
    
    public function actionTest62(){
        $sql='
                    SELECT
                    	COUNT(auction_limit.auction_id)
                    FROM
                    	auction_limit
                    LEFT JOIN auction_parame ON auction_limit.auction_id = auction_parame.auction_id
                    WHERE
                    	auction_parame.parame_name = "type"
                    AND auction_parame.parame_value = 3
                    AND auction_limit.winner_id = 1030
                ';
        var_dump(Yii::app()->db->createCommand($sql)->execute());
    }
    //对Authorize.net进行测试
    public function actionTest61(){
        $merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
        $merchantAuthentication->setName("9qB55G6Lf7");
        $merchantAuthentication->setTransactionKey("22EzzjV5n7n8V37M");
        $refId = 'ref' . time();
        
        $creditCard = new AnetAPI\CreditCardType();
        $creditCard->setCardNumber("4007000000027" );
        $creditCard->setExpirationDate( "2038-12");
        $paymentOne = new AnetAPI\PaymentType();
        $paymentOne->setCreditCard($creditCard);
        
        $transactionRequestType = new AnetAPI\TransactionRequestType(); //交易请求类
        $transactionRequestType->setTransactionType("authCaptureTransaction");//交易类型这个是什么意思？
        $transactionRequestType->setAmount(151.51);//设置交易金额
        $transactionRequestType->setPayment($paymentOne);//设置交易，把上面那个支付类型类传递过来
        $request = new AnetAPI\CreateTransactionRequest();//创建一个创建交易请求类
        $request->setMerchantAuthentication($merchantAuthentication);//设置验证类为上面那个类
        $request->setRefId( $refId);//设置ref值
        $request->setTransactionRequest($transactionRequestType);//设置交易请求
        $controller = new AnetController\CreateTransactionController($request);//创建 创建交易控制器类
        $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
        
        var_dump($response);
        
        if ($response != null)
        {
            $tresponse = $response->getTransactionResponse();
            if (($tresponse != null) && ($tresponse->getResponseCode()=="1"))
            {
                echo "Charge Credit Card AUTH CODE : " . $tresponse->getAuthCode() . "\n";
                echo "Charge Credit Card TRANS ID  : " . $tresponse->getTransId() . "\n";
            }
            else
            {
                echo "Charge Credit Card ERROR :  Invalid response\n";
            }
        }
        else
        {
            echo  "Charge Credit Card Null response returned";
        }    
    }
    
    public function actionTest60(){
        /* $title='2015年12月23日13:34    中甲        天津权健  3-0  大连阿尔滨';
        $teams=array(
            '天津权健'=>array(
                'img'=>'quanjian.jpg'
            ) ,
            '大连阿尔滨'=>array(
                'img'=>'aerbin.jpg'
            )
        );
        $titles=array_filter(explode(' ', $title));
        $teamNames=array_keys($teams);
        $imgs=array();
        var_dump($titles);
        foreach ($titles as $t){
            if (in_array($t, $teamNames)){
                var_dump(current($titles));
                break;
            }
        } */
    }
    
    public function actionTest59(){
        $redis=new Redis();
        $redis->connect('localhost',6379);
        var_dump($redis->flushDB());
    }
    
    public function actionTest58(){
        $auction=new AuctionDetailDao();
        $auction->find(209);
        
        if ($auction->status!=2){
            $auctionPool=AuctionPool::model()->findByAttributes(array(
                'auction_id'=>209
            ));
            $auction->winner_price=$auctionPool->winner_price;
        }
         
        $customer=Customer::model()->findByPk(1027);
        $userName=$customer->user_name;
        
        $bidLog=new AuctionBidLog();
        $bidLogNum=$bidLog->countByAttributes(array(
            'winner_name'=>$userName,
            'auction_id'=>209
        ));
        
        $bids=$bidLogNum;
        $costBidPrice=floatval(($bidLogNum+1)*0.65);
        $winnerPrice=floatval($auction->winner_price+$auction->winner_price_increment);
        $cost=$costBidPrice+$winnerPrice;
        $valuePrice=floatval($auction->value_price);
        
        var_dump($cost);
        var_dump($valuePrice);
        /* $auction=new AuctionDetailDao();
        $auction->find(209);
        
        if ($auction->status!=2){
            $auctionPool=AuctionPool::model()->findByAttributes(array(
                'auction_id'=>209
            ));
            $auction->winner_price=$auctionPool->winner_price;
        }
        var_dump($auction->attributes); */
        /* $auction=new AuctionDao();
        $auction->find(208); */
        /* $auction=new AuctionLiveDao();
        $auction->find(208);
        var_dump($auction->winner_price); */
      /*   $test=new TestModel();
        $test->validate();
        $error=$test->getErrors();
        if (array_key_exists('hello', $error)){
            var_dump('exists');
        } */
        /* $bid=new BidAuction();
        $bid->customerId=100;
        $bid->bid();
        $error=$bid->getErrors();
        if (array_key_exists('customerId', $error)){
            var_dump($error['customerId']);
        } */
        
       /* $auction=new AuctionDao();
       $auction->find(189);
       var_dump($auction->attributes);  */
        
        /* $customer=Customer::model()->findByPk(1027);
        $userName=$customer->user_name;
        var_dump($userName); */
        
        /* $bidLog=new AuctionBidLog();
        $bidLogNum=$bidLog->countByAttributes(array(
            'winner_name'=>'wlvgfe',
            'auction_id'=>124
        ));
        var_dump($bidLogNum); */
    }
    public function actionTestCheckEmail(){
        $email_confirm=$this->check_email(array('username'=>'172'));
        if($email_confirm){
            
        }else{
            $this->redirect(Yii::app()->params['site_url']."/register/sendmail");
        }
    }
    public function check_email($data){
        $return=$this->sendCurl($data, Yii::app()->params['egunner']."check_email.php");
        if(!empty($return)){
            $return_arr=json_decode($return);
            if($return_arr->result==true){
                return true;
            }
            else{
                return false;
            }
        }else{
            return false;
        }
    }
    public function actionJsonp(){
        $callback = isset($_GET['callback']) ? trim($_GET['callback']) : ''; //jsonp回调参数，必需
        $date["msg"]="err";
        $date["info"]="因人品问题，发送失败";
        $tmp= json_encode($date); //json 数据
        echo $callback . '(' . $tmp .')';  //返回格式，必需
    }
    public function sendCurl($data,$url){
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0 );
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        $output = curl_exec($ch);
        if (curl_errno($ch)) {
            echo 'Errno'.curl_error($ch);
        }
        curl_close($ch);
        return $output;
    }
    public function actionSendCurl(){
        $url = "http://localhost/penny_bidding1/05.develop/01.frontend/test/getcurl";
        $post_data = array ("username" => "bob","key" => "12345");
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0 );
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);       
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        $output = curl_exec($ch);
        if (curl_errno($ch)) {
            echo 'Errno'.curl_error($ch);
        }
        curl_close($ch);
    }
    public function actionGetCurl(){
        $data=$_REQUEST;
//         $data=$GLOBALS['HTTP_RAW_POST_DATA'];
        Yii::app()->cache->set("data", $data);
    }
    public function actionGetPost(){
        $data=Yii::app()->cache->get('data');
//         var_dump($data);
        var_dump($data);
        
    }
    public function actionGetRe(){
        $data=Yii::app()->cache->get('regis');
        //         var_dump($data);
        var_dump($data);
    
    }


    public function actionGetCache(){
        $a="01";
        $b="02";
        $c="2010";
        echo strtotime($a."/".$b."/".$c);
    }
    
    
    public  function actionTest56(){
        $model=new AuctionLiveDao();
        $model=$model->find(177);
        var_dump($model->attributes);
    }
    
    public function actionTest55(){
        $model=new InviteEmail('generate');
        var_dump($model->getScenario());
        var_dump($model->validate());
        var_dump($model->getErrors());
        $model->setScenario('register');
        var_dump($model->getScenario());
        var_dump($model->validate());
        var_dump($model->getErrors());
    }
    
    public function actionTest54(){
        $invited=new InviteEmail();
        $invited->generateUrl();
        var_dump($invited->url);
    }
    public function actionTest53(){
        $invited=new InviteEmail('generate');
        $invited->customerId=1027;
        $invited->getRef();
        //$invited->generateUrl();
        var_dump($invited->refer);
    }
    
    public function actionTest52(){
        $invited=new InviteEmail('register');
        $invited->email='102848fea9d713@qq.com';
        var_dump($invited->getCookie());
        if ($invited->validate()){
            var_dump(123);
            $invited->success();
        }
        var_dump($invited->getErrors());
    }
    
    public function actionTest51(){
        $invited=new InviteEmail('visit');
        $invited->refer=!empty($_GET['ref'])?$_GET['ref']:null;
        if ($invited->validate()){
            $invited->visit();
        }
        var_dump($invited->getErrors());
        var_dump($invited->getCookie());
   }
   
    public function actionTest50(){
        $invited=new InviteEmail('generate');
        var_dump(Yii::app()->user->id);
        $invited->attributes=array(
            'customerId'=>1027,
            'email'=>'102848fea9d71@qq.com'
        );
        if ($invited->validate()){
            $invited->generate();
        }
        var_dump($invited->refer);
        var_dump($invited->getErrors());
    }
    
    public function actionShare(){
        $cookie=Yii::app()->request->cookies['haha'];
        var_dump($cookie);
    }
    
    public function actionFlushdb(){
         $form=new AutoBidForm();
         $form->customer_id=15;
    }
    
	public function actionNow(){
        
        $now=time();
    	var_dump(strtotime('now'));
    	var_dump(date('Y-m-d', 1448428411));
    }
    public function actionTestIp(){
        Yii::app()->cache->set('test_ip',Yii::app()->tools->getIp(),3600*24);
        var_dump(Yii::app()->cache->get('test_ip'));die;
    }
    public function actionDelTestIp(){
        if(Yii::app()->cache->delete('test_ip')){
            echo "success";
        }else{
            echo "error";
        }
        
    }
    public function actionFrozen(){
        $frozen=new Frozen();
        $frozen->ip='117.11.100.148';
        $data=$frozen->getLoginCustomer('account');
        var_dump($data);die;
    }
    public function actionRefer(){
        $customerinfo=CustomerInfo::model()->findAll();
        foreach ($customerinfo as $k=>$v){
            $v->refer=$this->createUniqid();
            $v->update();
            sleep(1);
        }        
    }
    public static function createUniqid()
    {
        $tempStr = md5(time());
        return $tempStr[mt_rand(0,31)].uniqid();
    }
    public function actionLogin(){
        $email=Yii::app()->request->getParam('email',null);
        $callback=Yii::app()->request->getParam('callback',null);
        if((!empty($email)) && (!empty($callback))){            
            $customerinfo=Customer::model()->find('email="'.$email.'"');
            $login_auth=new SysAuth();
            $login_auth->id       = $customerinfo->id;
            $login_auth->username = $customerinfo->user_name;
            Yii::app()->user->test=array('callback'=>$callback);
            $result = LoginPlus::Login($login_auth);
        }else{
            Yii::app()->getRequest()->redirect(Yii::app()->baseUrl);
        }        
    }
	public function actionTest32(){
    	$info=new AuctionInfo();
    	$info=$info->countByAttributes(array('status'=>1));
    	var_dump($info);
    }
	public function actionTest31(){
    	$autobid=new Autobid();
    	$autobid->deleteAllByAttributes(array('auction_id'=>137));
    }
	public function actionTest30(){
    	$limit=new AuctionLimit();
    	$limit->deleteAllByAttributes(array('auction_id'=>137,'limit_type'=>'AUTO_BID'));
    }
	public function actionReflection(){
    	try {
    		//throw new CException(Yii::t('yii', 'hahah'));
    		var_dump(2);
    	}catch (Exception $e){
    		var_dump($e->getMessage());
    	}finally{
    		var_dump(1);
    	}
    }
	public function actionTest28(){
    	$auctionStatus=new AuctionStatus();
    	$auctionStatus->auctionId=129;
    	$auctionStatus->end();
    }
	public function actionTt1(){  
              $a = 'Reb is BaKa';
              $q = $a ?:'Xia Mi Bak';
              
              var_dump($q);
              //Reb is BaKa
              
              $a = null;
              $q = $a ?:'Xia Mi Bak';
              
              var_dump($q);
              //Xia Mi Bak
        
        exit();
        $limit = new AuctionLimitDao();
        
        $limit->customerId = 5;
        $limit->auctionId = 75;
        
        $limit->add(1447394400,'BUY_IT_NOW');
        
        $buyItNow = $limit->limit('BUY_IT_NOW');
        //var_dump($buyItNow);
        
    }
    
    public function actionAuct(){
        $bid = new BidDao();
        $bid->customerId = $_GET['cid'];
        //$bid->getBidModel('cash')->setEnv('parentTransaction');
        //$bid->getBidModel('cash')->setEnv('throw');
        $q = $bid->getBidModel('cash')->setBid(1000,'Bid_Test');
        var_dump($q);
        exit();
        Yii::import('dao.auction.AuctionLiveDao');
        $auctionStatus=new AuctionLiveDao();
        $auctionStatus = $auctionStatus->find(71);
        $q = $auctionStatus->avatar;
        var_dump($q);
    }
    
	public function actionTest17(){

	    Yii::import('application.dao.auction.AuctionStatus');
		$auctionStatus=new AuctionStatus();
		$auctionStatus->auctionId=76;
		$auctionStatus->end();
	}
	
	public function haha(){
		var_dump(1232);
	}
	
	public function actionTest16(){

	    Yii::import('dao.auction.AuctionStatus');
		$auctionStatus=new AuctionStatus();
		$auctionStatus->auctionId=83;
		$auctionStatus->end();
		$q = $auctionStatus->getErrors();
		var_dump($q); 
	}
	
	public function actionTest15(){
		$redis = Yii::app()->dbRedis;
		
		$redis->set('auction:100:1',1);
		$redis->set('auction:100:2',2);
		$redis->set('auction:100:3',3);
		$redis->set('auction:100:4',4);
		$redis->set('auction:100:5',5);
		$redis->set('auction:aaa',6);
		$q = $redis->getKeys('auction:100*');
		var_dump($q);
	}
	
	public function actionTest14(){
		$customerInfo=new customerCacheAuctionBidInfo();
		$customerInfo->customerId=1027;
		$customerInfo->auctionId=76;
		$customerInfo->addItems(array('hello'=>1,'hahah'=>2));
		var_dump($customerInfo->getItems());
	}
	
	public function actionTest13(){
		$redis=new Redis();
		$redis->connect('localhost',6379);
		var_dump($redis->hSet('hello','key1',100));
	}
	
	public function actionTest12(){
		$mark=new AuctionMarkDao();
		$mark->auction_id=78;
		var_dump($mark->del());
		var_dump($mark->add());
		var_dump($mark->get());
	}
	
	public function actionTest11(){
		$autobid=new AutoBidDao();
		$q=$autobid->run();
		var_dump($q);		
	}
	
	public function actionTest10(){
		$bid = new BidDao();
		$bid->customerId = 1027;
		try {
			$bid->getBidModel('cash')->setEnv('parentTransaction');
			$bid->getBidModel('cash')->setEnv('throw');
			$bid->getBidModel('cash')->setBid(1000,'BUY_BID');
			
			$bid->getBidModel('promo')->setEnv('parentTransaction');
			$bid->getBidModel('promo')->setEnv('throw');
			$bid->getBidModel('promo')->setBid(1000,'BUY_BID');
		}catch (Exception $e){
			
		}
		
		
		
		
		
		
		
		$q = $bid->getBidModel('promo')->setBid(1000,'BID_ACTION');
	}
	
	public function actionTest8(){
		$winner=new AuctionPool();
		$winner=$winner->findByAttributes(array('auction_id'=>72));
		var_dump($winner->winner_id);
		
		$bids=new CustomerBidAuctionCount();
		$bids=$bids->findByPk('72:1028:CASH');
		var_dump($bids->bid_num);
	}
	
	public function actionTest7(){
		$bidHistory=new AuctionHistoryList();
		$bidHistory->setHistoryKey(73);
		var_dump($bidHistory->getHistoryList());
	}
	
	public function actionTest4(){
		$auctionBid=new BidAuction();
		$auctionBid->customerId=1027;
		$auctionBid->auctionId=78;
		var_dump($auctionBid->bid());
		var_dump($auctionBid->getErrors());
	}
	
	public function actionTest6(){
		$auctionBid=new BidAuction();
		$auctionBid->customerId=1028;
		$auctionBid->auctionId=78;
		var_dump($auctionBid->bid());
		var_dump($auctionBid->getErrors());
	}
	
	public function actionTest5(){
		$auctionLimit = new AuctionLimitDao();
        $auctionLimit->auctionId = 54;
        $auctionLimit->customerId = 1027;
        $auctionLimit->add(time() + 1000,AuctionLimitDao::AUTO_BID_LIMIT);
        var_dump($auctionLimit->limit());
	}
	
	
	public function actionTest3(){
		$auctionLimit = new AuctionLimitDao();
        $auctionLimit->auctionId = 54;
        $auctionLimit->customerId = 1027;
        $auctionLimit->add(time() + 1000,AuctionLimitDao::AUTO_BID_LIMIT);
        var_dump($auctionLimit->limit());
	}
    public function actionTestar2(){
        
        
        $auctionLimit = new AuctionLimitDao();
        $auctionLimit->auctionId = 118;
        $auctionLimit->customerId = 1001;
        $auctionLimit->add(time() + 1000,AuctionLimitDao::AUTO_BID_LIMIT);
        var_dump($auctionLimit->limit());
        
        exit();
        
        $bidAuction = new BidAuction();
        $bidAuction->auctionId = 18;
        $bidAuction->customerId = 100;
        $q = $bidAuction->bid();
        
        var_dump($bidAuction->getErrors());
        var_dump($q);
        exit;
        
        
        Yii::import('dao.bid.BidDao');
        $bid = new BidDao();
        $bid->customerId = 100;
        $bid->getBidModel('promo')->setEnv('true',false);
        $q = $bid->getBidModel('promo')->setBid(-5,'BID_ACTION');
        
        var_dump($q);
        
        exit();
    }
    public function actionAboutus(){
    	$this->render('aboutus');
    }
    
    public function actionSiterules(){
    	$this->render('siterules');
    }
    
	public function actionTestar(){
	    Yii::app()->dbRedis->flushDB();
	    
	    
	    
	    exit();
	    
	    Yii::app()->dbRedis->flushDB();
	    
	    exit();
        
        Yii::import('dao.bid.BidDao');
        $bid = new BidDao();
        $bid->customerId = 2;
        $bid->getBidModel('cash')->setBid(1000,'test');
        
        exit();
        
        
        
        echo time();
        $bidAuction = new BidAuction();
        $bidAuction->auctionId = 18;
        $bidAuction->customerId = 1;
        $q = $bidAuction->bid();
        
        echo time();
        
        var_dump($q);
        var_dump($bidAuction->getBidAfterInfo());
        var_dump($bidAuction->getErrors());
        exit();
        
        Yii::import('dao.bid.BidDao');
        $bid = new BidDao();
        $bid->customerId = 1;
        $bid->getBidModel('cash')->amount = -12;
        $q = $bid->getBidModel('cash')->component('bidExpire')->run(1000);
        var_dump($q);
        
        exit();
            $bidAuction = new BidAuction();
            $bidAuction->auctionId = 18;
            $bidAuction->customerId = 1;
            $q = $bidAuction->bid();
       
        var_dump($q);
        var_dump($bidAuction->getBidAfterInfo());
         var_dump($bidAuction->getErrors());
        exit();
        
        Yii::import('dao.BidDao');
        $bid = new BidDao();
        $bid->customerId = 1;
        $q = $bid->getBidModel('cash')->setBid(100,'test');
        
        var_dump($q);
        
        exit();
       
        Yii::import('dao.BidDao');
        $bid = new BidDao();
        $bid->customerId = 1;
       $q = $bid->getBidModel('cash');
        
       var_dump($q->getBid());
        
        exit();
        Yii::import('dao.bid.CashBidModel');
        Yii::import('dao.bid.PromoBidModel');
        
        $cash = new CashBidModel();
        $cash->customer_id = 1;
        $cash->setBid(100,'test','134');
        $q = $cash->getBid();
        $q = $cash->getLastHistoryId();
        
        $promo = new PromoBidModel();
        $promo->customer_id = 1;
        $promo->setBid(100,'test','134');
        $q = $promo->getBid();
        $q = $promo->getLastHistoryId();
        
        var_dump($q);
        exit();
        
        Yii::import('application.components.auction.AuctionLimit');
        
        $limt = new AuctionLimit();
        $limt->auctionId = 2;
        $limt->customerId = 1;
        //$limt->add(time() + 100000,AuctionLimit::AUCTION_LIMIT);
        $limt->add(time() + 100000,AuctionLimit::AUTO_BID_LIMIT);
        $q = $limt->limit();
        var_dump($q);
        exit();
        
        Yii::import('application.components.bid.CashBidModel');
        
        $cash = new CashBidModel();
        $cash->customer_id = 1;
        $cash->setBid(-100,'test','134');
        $q = $cash->getBid();
        var_dump($q);
        exit();
        
        
        
        
        
        $bid=new BidDao();

		
		
		
		$bid->setCustomerId(1)
		->addBidAction('application.components.bid.CashBidModel',-100,'TEST BID','134134')
		->addBidAction('application.components.bid.CashBidModel',-100,'TEST BID','134134')
		->run();
		
		var_dump($bid->getErrors());
		
		exit();





		$bid = new BidAuction();
		$bid->auctionId = 4;
		$bid->customerId = 1;
		$bid->bid();

		var_dump($bid->getErrors());

		exit;
		Yii::app()->dbRedis;
			Yii::app()->dbRedis;
				Yii::app()->dbRedis;


		exit();
        Yii::app()->dbRedis->flushDB();
    	/* $bid=new BidDao();
    	$bid->setCustomerId(2)->earn(100,'CASH','BID_BID_BID')->cost(-200, 'CASH', 'BID_AUCTION')->run(); */
    	var_dump(time()); 
    	/* $arr='fexxxxfeyyyyyfe';
    	var_dump(explode('fe',$arr));
    	var_dump(array_filter(explode('fe',$arr))); */
    }
    
	public function actionTestpool(){
        /*
        $auctionCache = new AuctionCache();
        $save = $auctionCache->buildAllByAr();
        
        $auctionCache->findByPk(15);
        var_dump($auctionCache->attributes);
        */
        
        $auctionPool = new AuctionPool();
        $auctionPool = $auctionPool->findByPk(24);
        
        $auctionPool->status = 2;
        $auctionPool->save();
        
        
        var_dump($auctionPool->getErrors());
        exit();
        /*
        $auctionPool = new AuctionPool();
        $auctionPool->findByPk(9);
        $auctionPool->auction_id = 9;
        $auctionPool->winner_price = 100.00;
        $auctionPool->save();
        var_dump($auctionPool->getErrors());
        */
        
        
        $auctionData = array(
            'id' => '1',
            'auction_id' => '1',
            'start_time' => '1440997200',
            'end_time' => '1443589200' ,
            'winner_price_increment' =>  '0.00' ,
            'winner_price' =>  '23.00' ,
            'winner_time' =>  '0' ,
            'winner_id' =>  '0' ,
            'status' =>  '0' ,
        );
        Yii::app()->cache->set('auction_cache_index_'.$auctionData['id'],microtime());
        //$auctionData = $auction->attributes;
       
        Yii::app()->cache->set('auction_cache_data_'.$auctionData['id'],$auctionData);
    }
    
    public function actionSetver(){
        
        
        $auctionPool = new AuctionPool();
        $auctionPoolData = $auctionPool->findAll($auctionPool->searchRun()->getCriteria());
        
        if (!empty($auctionPoolData)){
            foreach ($auctionPoolData as $auction){
                Yii::app()->cache->set('auction_cache_index_'.$auction->id,microtime());
                $auctionData = $auction->attributes;
                Yii::app()->cache->set('auction_cache_data_'.$auction->id,$auctionData);
            }
        }
        /*
        for($i=1;$i<=5;$i++){
            Yii::app()->cache->set('auction_cache_index_'.$i,microtime());
            Yii::app()->cache->set('auction_cache_data_'.$i,array('id' => $i,'last_time' => 100));
        }
        Yii::app()->cache->set('auction_cache_data_1',array('id' => 1,'last_time' => 1000));
        */
        
        
        
        /*
        
        Yii::app()->cache->add('data_ver','134134');
        Yii::app()->cache->add('data_ver','134134123');
        Yii::app()->cache->set('data_ver','134131234');
                
        $path = Yii::getPathOfAlias('application.runtime.auction_ver');

        for($i=1;$i<=10;$i++){
            $name = $path.'\file_var';
            file_put_contents($name,'|'.time(),FILE_APPEND | LOCK_EX);
        }
       */
    }
    
    public function actionDao(){
        $q = Yii::import('application.components.auction.AuctionDao');
        //var_dump($q);
        $au = new AuctionDao();
    }
    
	public function actionDate(){
		echo '<pre>';
		echo date('Y-m-d H:i:s T');
		echo '<br>';
		echo time();
				
	}
	
	
	public function actionTest1(){
		$_SESSION['test'] = 134135;
		var_dump($_SESSION['test']);
	}
	
	public function actionTest2(){
		var_dump($_SESSION['test']);
	}
	
	public function actionTest(){
		echo '<pre>';
		
		$sendGrid = Yii::app()->sendGrid;
		
		$sendGrid->addTo('liu.hao@ebiz-interactive.com.cn');
		
		for($i = 0 ; $i <= 20 ; $i++){

			$sendGrid->setHtml('test'.$i);
			$send = $sendGrid->send();
			var_dump($send);
		}
		
		exit;
		/*
		Yii::app()->mail->welcome('duan.zhiyong@ebiz-interactive.com.cn','qwe');
		Yii::app()->mail->forgetpwd('duan.zhiyong@ebiz-interactive.com.cn','qwe');
		*/
		$startTime	= date('Y-m-d 00:00:0',mktime(0,0,0,date('m')-1,1,date('Y')));
		$endTime	= date('Y-m-d 23:59:59',mktime(0,0,0,date('m'),1,date('Y')) - 1);
		
		echo $startTime;
		echo '<pre>';
		echo $endTime;
		
	}
	
	public function actionPaymenttst(){
		require_once 'protected/extensions/authorizeNetPHPSDK/AuthorizeNet.php';
		
		$apit = new AuthorizeNetAIM('9T4JqAbB2h4','55Sue8DT3w4R647N');
		
		$apit->setFields(array(
				'amount'   => 0.01,
				'card_num'   => 5474151303726779,
				'exp_date'   => '06/2017',
				'first_name'  => 'hua',
				'last_name'  => 'wang',
				'address'   => '5968 temple city blvd, temple city, CA 91780',
				'city'    => 'temple city',
				'state'   => 'CA',
				'country'   => 'usa',
				'zip'   => '91780',
				'email'   => 'aurora318@gmail.com',
				'card_code'  => '982',
				'invoice_num' => 'd1d4e5770a740543b',
				'description' => 'dibzees',
				'phone'   => '1234567890',
				'header_email_receipt' => "<img src=\"http:\/\/www.dibzees.com\/images\/logo.png\" \/>",
		));
		$apit->setSandbox(false);
		$return = $apit->authorizeAndCapture();
		//$apit->setSandbox(false);
		echo '<pre>';
		
		var_dump($return);
		
		
		exit();
		
	}
	
	public function actionRegister(){
		Yii::app()->user->logout();
		$register = new Register(array(
			new RDCustomer(),		
		));
		
		$register->RDCustomer->email 			= 'test4@sina.com';
		$register->RDCustomer->password			= 'password';
		$register->RDCustomer->user_name		= 'test4';
		$register->RDCustomer->confirm_email	= 'test4@sina.com';
		$register->RDCustomer->created_ip		= Yii::app()->tools->getIp();
		
		//var_dump($register->RDCustomer->errors);
		
		$register->process(RPCustomer::name())->save();
		
	}
	
	public function actionIndex(){
		//Yii::app()->user->logout();
		
		$login = new Login(Login::LOGIN_EP);
		
	
		$login->identity(array(
			'email'		=> 'test1@test.com',
			'password'	=> 'password',	
		))->login();
		
		var_dump(Yii::app()->user->isGuest);
		exit();
	}
	
	public function actionReport(){
		$earbid = EarnedBidLog::model()->findAll(' bid_source_type = 2 ');
		foreach ($earbid as $val){
			$reportService = new ReportService();
			$attributes = $reportService->setCustomerId($val->customer_id)->initialAffiliateTrackingReportAttributes();
			if($val->bid_source_type==2){
				$attributes['active_customer'] = $val->customer_id;
				$attributes['purchased_bids'] = $val->customer_id;
				$attributes['total_bid_packs'] = 1;
				$attributes['total_bid_packs_price'] = $val->value;
				$attributes['bid_pack_user'] = $val->customer_id;
			}else{
				$attributes['active_customer'] = $val->customer_id;
			}
			$m = new ReportAffiliateTracking;
			$m->attributes = $attributes;
			$m->addAffiliateCodeUac();
		}
		exit();
	}
	
	public function actionResendEmail(){
	    $mailer = new YiiMailer();
        $mailer->setView('referral');//调用模板
        $mailer->setData(array('USER_NAME'=>'aaa','AMOUNT'=>'10','PRIZE_NAME'=>'10','DATE_OF_WIN'=>'1/1/2000','TOTAL_COST'=>'20','LAST_DAY'=>'2/2/2000','LINK_TO_PAY'=>'link'));//所需数据
        //发送到邮箱
        $mailer->AddAddress("zl13821868911@163.com");//目标邮箱
        
        $mailer->Subject = Yii::t('demo', 'referral');//标题
        if(!$mailer->Send()) {
            echo "Mailer Error: " . $mailer->ErrorInfo;
            die;
        } 
	}
	
	public function testEmail($email,$subject,$message){
		$mail = new YiiMailer();
		$mail->setFrom('support@dibzees.com', 'Dibzees.com');
		$mail->setTo($email);
		$mail->setSubject($subject);
		$mail->setBody($message);
		$return['emailInfo'] = $mail->Body;
		$return['succes'] = $mail->send();
		return $return;
	}
	
	public function actionPaymentTest(){
		require_once 'protected/extensions/authorizeNetPHPSDK/AuthorizeNet.php';
		$paymentInfo = array(
			''		
		);
		
		$apit = new AuthorizeNetAIM(
				Yii::app()->params['paymentAPI']['authorizeNet']['account']['api_login_id'],
				Yii::app()->params['paymentAPI']['authorizeNet']['account']['transaction_key']				
		);
		
		$apit->setFields(array(
				'amount' 		=> 0.01,
				'card_num' 		=> 4111111111111111,
				'exp_date' 		=> '12/2014',
				'first_name' 	=> 'hua',
				'last_name'		=> 'wang',
				'address' 		=> '5968 temple city blvd',
				'city' 			=> 'temple city',
				'state' 		=> 'CA',
				'country' 		=> 'usa',
				'zip'			=> '91780',
				'email'			=> 'aurora318@gmail.com',
				'card_code' 	=> '123',
				'invoice_num'	=> 'd1d4e5770a740543b',
				'description'	=> 'dibzees',
				'phone'			=> '1234567890',
				'header_email_receipt'	=>	"<img src=\"http:\/\/www.dibzees.com\/images\/logo.png\" \/>",
		));
		
		$return = $apit->authorizeAndCapture();
		
		echo '<pre>';
		
		var_dump($return);
		
		
		exit();
		
		
		$api = new AuthorizeNet($paymentInfo);
		$api->apiRequest();
		$response = $api->apiResponse();
		if ($api->apiPaymentVaild()){
			if(is_object($paymentInfo->bidPack)){
				$buyBid = new PaymentBuyBid($paymentInfo);
				$buyBid->setProcessInfo(array('paymentType' => 2));
				$buyBid->save()->redirect();
			}
			if(is_object($paymentInfo->orderInfo)||is_object($paymentInfo->buyItNow)){
				$buyAuction = new PaymentBuyAuction($paymentInfo);
				$buyAuction->setProcessInfo(array('paymentType' => 2));
				$buyAuction->save()->redirect();
			}
		}else{
			Yii::app()->session['paymentError'] = array(
					'paymentCode'	=>	$paymentCode,
					'paymentType'	=>	AuthorizeNet::API_NAME,
			);
			$couponCodeValidService = new CouponCodeVerificationService();
			$couponCodeValidService->setCouponCode($paymentInfo->coupon_code)->addCouponCode();
		
			$api->paymentLog(json_encode($response));
			$model = new PaymentLog();
			$model->type = 2;
			$model->request = $paymentCode;
			$model->customer_id = Yii::app()->user->id;
			$model->created = time();
			$model->response = json_encode(json_encode($response));
			$model->save();
		
			Yii::app()->session['payment_error'] = 'Please try using PayPal or call your Bank/Credit Card Company and ask them to approve transactions to Dibzees, LLC. If you have further questions, please contact Dibzees support at: support@dibzees.com!';
			$this->redirect(Yii::app()->baseUrl.'/account');	
		}
	}
	public function actionCacheEcho(){
	    var_dump(Yii::app()->cache->get('mark_43'));
	    
	    var_dump(Yii::app()->cache->get('mark_ip_52'));
	    var_dump(Yii::app()->tools->getIp());
	    die;
	}
	public function actionDelCacheEcho(){
	    Yii::app()->cache->delete('mark');
	    Yii::app()->cache->delete('mark_ip');
	    die;
	}
	
	public function actionTest100(){
	    $criteria=new CDbCriteria();
	    $criteria->limit=100;
	    $customer=new Customer();
	    $customers=$customer->findAll($criteria);
	    $result=array();
	    foreach ($customers as $c){
	        $result[$c->user_name]=array(
	            'id'=>$c->id,
	            'username'=>$c->user_name,
	            'email'=>$c->email,
	            'created'=>$c->created
	        );
	    }
	    echo json_encode($result);
	}
}

